package server;

import hibernate.Factory;

import java.util.List;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import api.Person;

/**
 * @author Ann Raboschuk
 */
public class Server implements IAmServer
{
   private static final long serialVersionUID = 1L;

   public static void main(String args[]) 
	   { 
			ApplicationContext context = new
			ClassPathXmlApplicationContext("server_config.xml");

			context.getBean("rmservice");
			
			System.out.println("Server is ready."); 
	   } 
	
	public Server(){}
	
   @Override
   public Long add(Person person)
   {
      return Factory.getInstance().getPersonDAO().addPerson(person);
   }

   @Override
   public void delete(Person person)
   {
      Factory.getInstance().getPersonDAO().deletePerson(person);
   }

   @Override
   public void edit(Person person)
   {
      Factory.getInstance().getPersonDAO().updatePerson(person);
   }

   @Override
   public List<Person> loadAll()
   {
      return Factory.getInstance().getPersonDAO().getAllPersons();
   }

   @Override
   public Person getPersonById(Long id)
   {
      return Factory.getInstance().getPersonDAO().getPersonById(id);
   }
}
